
import java.sql.*;
public class DbUtil {

    public static String url = "jdbc:mysql://localhost:3306/java12?useSSL=false&characterEncoding=UTF-8&serverTimezone=GMT%2b8";

    public static Connection getConnection(String user, String password) {
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
        Connection con = null;

        try {
            con = DriverManager.getConnection(url, user, password);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        return con;
    }

    public static Statement getStatement(Connection con) {
        Statement st = null;
        try {
            st = con.createStatement();
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        return st;
    }

    public static boolean closeResultSet(ResultSet re) {
        try {

            re.close();
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        return true;
    }

    public static boolean setClose(Connection con, Statement st) {
        try {
            st.close();
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        try {
            con.close();
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        return true;
    }
}
